import Vue from 'vue'
import Router from 'vue-router'

// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)

/* Layout */
import Layout from '../views/layout/Layout'

/**
 * hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
 *                                if not set alwaysShow, only more than one route under the children
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noredirect           if `redirect:noredirect` will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
  }
 **/
export const constantRouterMap = [
  { path: '/404', component: () => import('@/views/404'), hidden: true },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    redirect: '/login/',
    name: 'Login',
    hidden: true,
    children: [
      {
        path: '',
        component: () => import('@/views/login/components/login')
      },
      {
        path: 'forgetPwd',
        name: 'ForgetPwd',
        component: () => import('@/views/login/components/forgetPwd'),
      },
      {
        path: 'resetPwd',
        name: 'ResetPwd',
        component: () => import('@/views/login/components/resetPwd'),
      }
    ]
  },
  {
    path: '/register',
    component: () => import('@/views/register/index'),
    redirect: '/register/first',
    name: 'Register',
    hidden: true,
    children: [
      {
        path: 'first',
        name: 'First',
        component: () => import('@/views/register/first/index')
      },
      {
        path: 'second',
        name: 'Second',
        component: () => import('@/views/register/second/index')
      },
      {
        path: 'third',
        name: 'Third',
        component: () => import('@/views/register/third/index')
      },
      {
        path: 'fourth',
        name: 'Fourth',
        component: () => import('@/views/register/fourth/index'),
        redirect: '/fourth/review',
        children: [
          {
            path: 'review',
            component: () => import('@/views/register/fourth/review')
          },
          {
            path: 'failure',
            component: () => import('@/views/register/fourth/failure')
          },
          {
            path: 'success',
            component: () => import('@/views/register/fourth/success')
          }
        ]
      }
    ]
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    name: 'Dashboard',
    meta: { title: '工作台', icon: 'table' },
    children: [{
      path: 'dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '工作台', icon: 'dashboard' }
    }]
  },
  {
    path: '/draft',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'index',
        name: 'draft',
        component: () => import('@/views/draft/index'),
        meta: { title: '草稿箱', icon: 'form' }
      }
    ]
  },
  {
    path: '/setting',
    component: Layout,
    redirect: '/setting/account',
    name: 'setting',
    meta: { title: '设置', icon: 'setting' },
    children: [
      {
        path: 'account',
        name: 'account',
        component: () => import('@/views/setting/account/index'),
        meta: { title: '账户详情' }
      }
    ]
  },
  {
    path: '/manage',
    component: Layout,
    redirect: '/manage/comments',
    name: 'manage',
    meta: { title: '管理', icon: 'manage' },
    children: [
      {
        path: 'comments',
        name: 'comments',
        component: () => import('@/views/manage/comments/index'),
        meta: { title: '留言管理' }
      }
    ]
  },
  {
    path: '/check',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'check',
        component: () => import('@/views/check/index'),
        meta: { title: '审核', icon: 'check' }
      }
    ]
  },
  { path: '*', redirect: '/404', hidden: true }
]

export default new Router({
  // mode: 'history', //后端支持可开
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})
